window.addEventListener("load", function () {
	// 勾选同意注册
	let flag = 1;
	$("#choose").addEventListener("change", function () {
		if (flag) {
			$(".btn").disabled = false;
			$(".btn").style.backgroundColor = "#00bdff";
			$(".btn").style.color = "#fff";
			flag = 0;
		} else {
			$(".btn").disabled = true;
			$(".btn").style.backgroundColor = "#e0e0e0";
			$(".btn").style.color = "#5f5f5f";
			flag = 1;
		}
	});
	// 表单验证方法二:
	$(".btn").addEventListener("click", function (e) {
		const regExp1 = /\w{6,12}/;
		const regExp2 =
			/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
		const regExp3 = /[0-9]{6}/;
		let usernameValue = $("#username").value;
		let numberValue = $("#number").value;
		let judgeValue = $("#judge").value;
		let passwordValue = $("#password").value;
		verify(regExp1.test(usernameValue), "#username");
		verify(regExp2.test(numberValue), "#number");
		verify(regExp3.test(judgeValue), "#judge");
		verify(regExp1.test(passwordValue), "#password");
		e.preventDefault();
	});

	function verify(condition, node) {
		if (condition) {
			$(node).previousElementSibling.style.display = "none";
		} else {
			$(node).previousElementSibling.style.display = "block";
		}
	}

	// 表单验证方法一:
	/* $(".btn").addEventListener("click", function () {
		let usernameValue = $("#username").value;
		let numberValue = $("#number").value;
		let judgeValue = $("#judge").value;
		let passwordValue = $("#password").value;
		let cd1 = usernameValue.length < 6 || usernameValue.length > 12;
		let cd2 = numberValue.length !== 11;
		let cd3 = judgeValue.length !== 6;
		let cd4 = passwordValue.length < 6 || passwordValue.length > 12;
		verify(cd1, "#username");
		verify(cd2, "#number");
		verify(cd3, "#judge");
		verify(cd4, "#password");
	});

	function verify(condition, node) {
		if (condition) {
			$(node).previousElementSibling.style.display = "block";
		} else {
			$(node).previousElementSibling.style.display = "none";
		}
	} */

	// 点击获取验证码倒计时
	let num = 60;
	$("#getCode").addEventListener("click", function () {
		timer = window.setInterval(function () {
			if (num < 10) {
				$("#getCode").textContent = `倒计时0${num}s`;
				$("#getCode").disabled = true;
			} else {
				$("#getCode").textContent = `倒计时${num}s`;
				$("#getCode").disabled = true;
			}
			if (num < 0) {
				window.clearInterval(timer);
				$("#getCode").textContent = `获取验证码`;
				$("#getCode").disabled = false;
			}
			num--;
		}, 1000);
	});
});
